<% content_for :page_title do %>
  <%= plural_resource_name(Spree::Property) %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:new_property), new_object_url, { class: "btn-success", icon: 'add.svg', 'data-update' => 'new_property', id: 'new_property_link' } %>
<% end if can?(:create, Spree::Property) %>

<% content_for :table_filter do %>
  <div data-hook="admin_property_sidebar">
    <%= search_form_for [:admin, @search] do |f| %>

      <%- locals = {f: f} %>

      <div class="row">
        <div class="col-12 col-lg-6">
          <div data-hook="admin_property_index_search" class="form-group">
            <%= f.label :name_cont, Spree.t(:name) %>
            <%= f.text_field :name_cont, class: "form-control js-quick-search-target js-filterable" %>
          </div>
        </div>

        <div class="col-12 col-lg-6">
          <div class="form-group">
            <%= f.label :presentation_cont, Spree.t(:presentation) %>
            <%= f.text_field :presentation_cont, class: "form-control js-filterable" %>
          </div>
        </div>
      </div>

      <div class="form-actions" data-hook="admin_pproperties_index_search_buttons">
        <%= button Spree.t(:search), 'search.svg' %>
      </div>

    <% end %>
  </div>
<% end %>

<% if @properties.any? %>
<div class="table-responsive">
  <table class="table" id='listing_properties' data-hook>
    <thead>
      <tr data-hook="listing_properties_header">
        <th><%= Spree.t(:name) %></th>
        <th><%= Spree.t(:presentation) %></th>
        <th class="actions"></th>
      </tr>
    </thead>
    <tbody>
      <% @properties.each do |property| %>
        <tr id="<%= spree_dom_id property %>" data-hook="listing_properties_row">
          <td><%= property.name %></td>
          <td><%= property.presentation %></td>
          <td class="actions actions-2 text-right">
            <%= link_to_edit(property, no_text: true) if can?(:edit, property) %>
            <%= link_to_delete(property, no_text: true) if can?(:delete, property) %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>
<% else %>
  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::Property)) %>,
    <%= link_to Spree.t(:add_one), new_object_url if can?(:create, Spree::OptionType) %>!
  </div>
<% end %>

<%= paginate @collection, theme: 'admin-twitter-bootstrap-4' %>
